<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="cancel"
      @confirm="confirm"
    />
  </div>
</template>
<script>
import { editUserinfo_api } from "@/api/user.js";
import moment from "moment";
export default {
  data() {
    return {
      //   显示日期数据
      minDate: new Date(1970, 1, 1),
      maxDate: new Date(2020, 12, 31),
      currentDate: new Date(),
    };
  },
  methods: {
    cancel() {
      this.$emit("birthfunc");
    },
    async confirm() {
      const { data: res } = await editUserinfo_api({
        birthday: moment(this.currentDate).format("YYYY-MM-DD"),
      });
      this.currentDate = res.data.birthday;
      this.$emit("birthfunc", res.data.birthday);
    },
  },
};
</script>
<style lang='less' scoped>
</style>